home *** CD-ROM | disk | FTP | other *** search
/ NEC SuperScript 860 Solutions / NEC SuperScript 860 Solutions.iso / internet / scripts.lib / PHONE.SCR < prev    next >
Text File  |  1994-12-29  |  5KB  |  266 lines

  1. !
  2. !  Copyright (c) 1994
  3. !  by CompuServe Incorporated, Columbus, Ohio
  4. !
  5. !  The information in this software is subject to change without
  6. !  notice and should not be construed as a commitment by CompuServe.
  7. !
  8. !  PHONE:
  9. !    Contains modem/phone related logic.
  10. !    Success:  returns %Success
  11. !    Failure:  saves error msg in %FailureMsg and returns %Failure
  12. !
  13. !+V
  14. ! "3.5.2"
  15. !-V
  16.  
  17. MdmCmd = "";
  18. Z_Sent = %FALSE;
  19.  
  20. WaitTime = 10;
  21. ifndef %mdm_UserID = "";
  22. ifndef %mdm_Password = "";
  23. ifndef %mdm_ECOn = "";
  24. ifndef %mdm_DCOn = "";
  25.  
  26. if %DialType = 2 goto Direct_Connect;
  27.  
  28. goto Do_Phone_Connect;
  29.  
  30. !
  31. ! Subroutines
  32. !
  33. Hangup_Before_Connect:
  34.     define %LOCAL = 2;
  35.     call %Dir & "disconct.scr" () : Result;
  36.     return;
  37.  
  38. Two_Tries_Hangup:
  39.     gosub Hangup_Before_Connect;
  40.     goto Send_Reset_String;
  41.  
  42.  
  43. !
  44. ! Main Program:  Start_Connect
  45. !
  46. Do_Phone_Connect:
  47.     RingLimit = 5;
  48.     RingCount = 0;
  49.     UsingModem = %FALSE;
  50.     on cancel goto Phone_Cancelled;
  51.  
  52.     if %DialType = 0 goto Get_Tone_Str;
  53.     DialTypeStr = %mdm_Pulse_Dial;        ! Type = DT_Pulse
  54.     goto Init_Modem;
  55.  
  56. Get_Tone_Str:
  57.     DialTypeStr = %mdm_Tone_Dial;        ! Type = DT_Tone
  58.  
  59. Init_Modem:
  60.     show "Initializing modem";
  61.     MsgStr = "Dialing " & %Phone;
  62.     tries = 0;
  63.  
  64. Send_Reset_String:
  65.     if (%mdm_Reset = "") goto Modem_OK;
  66.     sendm %mdm_Prefix;
  67.     sendm %mdm_Reset;
  68.     sendm %mdm_Suffix;
  69.  
  70. Send_Wait:
  71.     wait
  72.         "User Id"    goto Send_User_ID,
  73.         "Password"    goto Send_Password,
  74.         %mdm_Ack    goto Modem_OK,
  75.         "0"        goto Modem_OK,
  76.         "ERROR"        goto Send_Z
  77.     until 40;
  78.  
  79.     tries = tries + 1;
  80.     if tries = 2 goto Two_Tries_Hangup;    ! Two failures to send Reset -
  81.                         ! hang up and try twice more.
  82.     if tries < 4 goto Send_Reset_String;
  83.  
  84.     wait until WaitTime;
  85.  
  86.     define %ErrorCode = 10;
  87.     FailStr = "Modem not responding";
  88.     goto Phone_Failed;
  89.  
  90. Send_User_ID:
  91.     !
  92.     ! For those modems that support password security...
  93.     !
  94.     send %mdm_UserID & "^M";
  95.     goto Send_Wait;
  96.  
  97. Send_Password:
  98.     !
  99.     ! For those modems that support password security...
  100.     !
  101.     send %mdm_Password & "^M";
  102.     wait
  103.         "User id"    goto Modem_Security_Error,
  104.         %mdm_Ack    goto Send_Reset_String,
  105.         "0"        goto Send_Reset_String
  106.     until 100;
  107.     goto Send_Reset_String;
  108.  
  109. Modem_Security_Error:
  110.     define %ErrorCode = 11;
  111.     define %FailureMsg = "Invalid modem security User ID or password";
  112.     exit %Fatal;
  113.  
  114. Send_Z:
  115.     if %mdm_Reset = "Z" goto Modem_OK;
  116.     if Z_Sent goto Modem_OK;
  117.     wait until 5;
  118.     Z_Sent = %TRUE;
  119.     sendm %mdm_Prefix;
  120.     sendm "Z";
  121.     sendm %mdm_Suffix;
  122.     goto Send_Wait;
  123.  
  124. Modem_OK:
  125.     wait until 10;
  126.     if (%mdm_Init = "") goto Check_Modem_Speaker;
  127.     sendm %mdm_Init;
  128.  
  129.     wait
  130.         %mdm_Ack    goto Check_Modem_Speaker,
  131.         "ERROR"        goto Show_Init_Error
  132.     until 33;
  133.     FailStr = "Modem not responding";
  134.     define %ErrorCode = 12;
  135.     goto Phone_Failed;
  136.  
  137. Show_Init_Error:
  138.     show "Error in modem command";
  139.     wait until 10;
  140.  
  141. Check_Modem_Speaker:
  142.     if (%mdm_Speaker <> 0) goto Check_DC;
  143.     MdmCmd = "M0";
  144.  
  145. Check_DC:
  146.     if %mdm_DCOn = "" goto Check_EC;
  147.     MdmCmd = MdmCmd & %mdm_DCOn;
  148.     goto Wait_Ack;
  149.  
  150. Check_EC:
  151.     if %mdm_ECOn = "" goto Wait_Ack;
  152.     MdmCmd = MdmCmd & %mdm_ECOn;
  153.  
  154. Wait_Ack:
  155.     if MdmCmd = "" goto Try_Phone;
  156.     wait until 2;            ! delay for 300 baud modems
  157.     sendm %mdm_Prefix & MdmCmd & %mdm_Suffix;
  158.  
  159.     wait
  160.         %mdm_Ack    goto Try_Phone,
  161.         "ERROR"        goto Show_Proto_Error
  162.     until 33;
  163.     goto Try_Phone;
  164.  
  165. Show_Proto_Error:
  166.     show "Error in modem command";
  167.  
  168. Try_Phone:
  169.     wait until 10;
  170.     count = 0;
  171.     FailStr = "";
  172. Dial_Phone:
  173.     if (count > %Retry) goto Exit_Error;
  174.  
  175.     show MsgStr;
  176.     
  177.     sendm %mdm_Prefix;
  178.     sendm DialTypeStr & %Phone;
  179.     sendm %mdm_Suffix;
  180.  
  181. Start_Phone_Loop:
  182.     wait
  183.         %mdm_Success    goto Modem_Success,
  184.         %mdm_Failure    goto Modem_Failure,
  185.         "No Dial"    goto No_Dial_Tone,
  186.         "Dial Complete"    goto Dial_Complete,
  187.         "Busy"        goto Line_Busy,
  188.         "Ring"        goto Remote_Ring
  189.     until 556;
  190.  
  191.     FailStr = "Dialing failed";
  192.     goto End_Phone_Loop;
  193.  
  194. Modem_Success:
  195.     wait until 5;
  196. Direct_Connect:
  197.     exit %Success;
  198.  
  199. Modem_Failure:
  200.     FailStr = "Dialing unsuccessful";
  201.     wait until WaitTime;
  202.     goto End_Phone_Loop;
  203.  
  204. No_Dial_Tone:
  205.     FailStr = "No Dialtone";
  206.     define %ErrorCode = 13;
  207.     goto Exit_Failure;
  208.  
  209. Dial_Complete:
  210.     MsgStr = "Dialed " & %Phone & ", awaiting answer";
  211.     show MsgStr;
  212.     goto Start_Phone_Loop;
  213.  
  214. Line_Busy:
  215.     FailStr = "Number is busy";
  216.     wait until 2 * WaitTime;
  217.     send %CR;
  218.  
  219.     wait
  220.         %mdm_Success    goto End_Line_Busy,
  221.         %mdm_Failure    goto End_Line_Busy,
  222.         "No Dial"    goto End_Line_Busy,
  223.         "Dial Complete"    goto End_Line_Busy,
  224.         "Busy"        goto End_Line_Busy,
  225.         "Ring"        goto End_Line_Busy
  226.     until 56;
  227.  
  228. End_Line_Busy:
  229.     wait until WaitTime;
  230.     goto End_Phone_Loop;
  231.  
  232. Remote_Ring:
  233.     RingCount = RingCount + 1;
  234.     if RingCount <= RingLimit goto Show_Ringing;
  235.  
  236.     FailStr = "No answer";
  237.     goto End_Phone_Loop;
  238.  
  239. Show_Ringing:
  240.     MsgStr = %Phone & " is ringing, awaiting answer";
  241.     show MsgStr;
  242.     goto Start_Phone_Loop;
  243.  
  244. End_Phone_Loop:
  245.     MsgStr = FailStr & ", redialing " & %Phone;
  246.     count = count + 1;
  247.     goto Dial_Phone;
  248.  
  249. Phone_Cancelled:
  250.     gosub Hangup_Before_Connect;
  251.     exit Result;
  252.  
  253. Phone_Failed:
  254.     if FailStr <> "" goto Exit_Fatal;
  255.     FailStr = "Dialing failed";
  256.  
  257. Exit_Fatal:
  258.     define %FailureMsg = FailStr;
  259.     exit %Fatal;
  260.  
  261. Exit_Error:
  262.     define %ErrorCode = 14;
  263. Exit_Failure:
  264.     define %FailureMsg = FailStr;
  265.     exit %Failure;
  266.